/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ep.m005.bl;

import ep.persistence.controllers.T009MedicineJpaController;
import ep.persistence.entities.T009Medicine;
import java.util.Collection;
import javax.persistence.Query;

/**
 *
 * @author Spyros
 */
public class BL005Controller {

    public Collection<T009Medicine> getMedicineBySubstance(String substance) {
        String queryString = "select distinct m.* "
                + "from t009_medicine m "
                + "inner join t009_t010 tt on tt.t009_medicine_id = m.id "
                + "inner join t010_substance s on s.id = tt.t010_substance_id "
                + "where s.name like '%"+substance+"%' ";
        T009MedicineJpaController jpaController = new T009MedicineJpaController();
        Query query = jpaController.getEntityManager().createNativeQuery(queryString, T009Medicine.class);
//        query.setParameter(1, substance);
        return query.getResultList();
    }

    public Collection<T009Medicine> getMedicineByMedName(String medName) {
        String queryString = "SELECT * FROM t009_medicine t WHERE t.name like '%"+medName+"%'";
        T009MedicineJpaController jpaController = new T009MedicineJpaController();
        Query query = jpaController.getEntityManager().createNativeQuery(queryString, T009Medicine.class);
        return query.getResultList();
    }
}
